Rails检查has_many是否存在(Rails check if has_many exist)
在rails中是否有办法检查查询中父项集合是否为零? 我希望得到所有没有孩子的父母。 例:
parent_with_no_child = Parent.find(:all, :include => :childs, :conditions => {:childs => :childs.exist?})
Is there a way in rails to check to see if a parents collection is nil in the query? I want to get all the parents that don't have any children. Example:
parent_with_no_child = Parent.find(:all, :include => :childs, :conditions => {:childs => :childs.exist?})
原文:https://stackoverflow.com/questions/5679693
最满意答案
两种解决方案
1)从
ConfigurationChanges = ConfigChanges.ScreenSize|ConfigChanges.Orientation
删除|ConfigChanges.Orientation
,这意味着您的活动将在屏幕旋转时重新创建。2)在
OnConfigurationChanged
方法中,在SetImageToToolbar();
之上添加以下代码SetImageToToolbar();
方法,如下所示:public override void OnConfigurationChanged(Configuration newConfig) { base.OnConfigurationChanged(newConfig); ToolbarResource = Resource.Layout.CustomToolbar; global::Xamarin.Forms.Forms.Init(this, null); LoadApplication(new App()); SetImageToToolbar(); }
为什么要添加这些代码?
我认为在屏幕旋转时你的代码中的
imgView
有问题,所以我认为OnCreate()
方法中的代码会有所帮助。更新:
第二种解决方案存在问题,如果你有很多页面,它会出错,所以我提供了另一种解决方案,使用自定义的
NavigationPageRenderer
:1)在您的pcl中添加
MyNavigationPage
:namespace ToolbarTestApp { class MyNavigationPage:NavigationPage { public MyNavigationPage(Page root) : base(root) { } } }
2)替换
MainPage = new MyNavigationPage(new TestPage());
withMainPage = new NavigationPage(new TestPage());
3)在你的android项目中添加
MyNavigationPageRender
:[assembly: ExportRenderer(typeof(MyNavigationPage), typeof(MyNavigationPageRender))] namespace ToolbarTestApp.Droid { class MyNavigationPageRender : NavigationPageRenderer { public MyNavigationPageRender(Context context) : base(context) { } protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); (Xamarin.Forms.Forms.Context as MainActivity).SetImageToToolbar(); } } }
将您的
SetImageToToolbar
方法更改为public,并且您无需重写OnConfigurationChanged
方法,只需将其删除即可。Two solutions:
1) Remove
|ConfigChanges.Orientation
fromConfigurationChanges = ConfigChanges.ScreenSize|ConfigChanges.Orientation
, that mean your activity will recreate when your screen rotate.2) Add below code in your
OnConfigurationChanged
method, above theSetImageToToolbar();
method, like this:public override void OnConfigurationChanged(Configuration newConfig) { base.OnConfigurationChanged(newConfig); ToolbarResource = Resource.Layout.CustomToolbar; global::Xamarin.Forms.Forms.Init(this, null); LoadApplication(new App()); SetImageToToolbar(); }
Why should you add these code?
I think there is something wrong in the
imgView
in your code when screen rotating, so I think the codes inOnCreate()
method will help it.Update:
There is something wrong in the second solution, if you have many pages, it will go wrong, so I provide another solution, use custom
NavigationPageRenderer
:1) Add
MyNavigationPage
in your pcl:namespace ToolbarTestApp { class MyNavigationPage:NavigationPage { public MyNavigationPage(Page root) : base(root) { } } }
2) Replace
MainPage = new MyNavigationPage(new TestPage());
withMainPage = new NavigationPage(new TestPage());
3)Add
MyNavigationPageRender
in your android project:[assembly: ExportRenderer(typeof(MyNavigationPage), typeof(MyNavigationPageRender))] namespace ToolbarTestApp.Droid { class MyNavigationPageRender : NavigationPageRenderer { public MyNavigationPageRender(Context context) : base(context) { } protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); (Xamarin.Forms.Forms.Context as MainActivity).SetImageToToolbar(); } } }
Change your
SetImageToToolbar
method to public, and you needn't overrideOnConfigurationChanged
method, just remove it.
相关问答
更多-
旋转图像问题(Rotating an image problem)[2022-04-19]
只需从下面的链接中输入代码即可: 将图像旋转到同一中心 just put the code from the following link as it :Rotate the image on the same center -
用鼠标旋转图像(Rotating an image with the mouse)[2023-10-26]
我假设每次鼠标移动更新都会调用resize() 。 您的问题似乎是self.angle += 1 ,这使您在每个鼠标事件上更新角度1度。 你的问题的解决方案是:在图像上选择旋转将居中的点(在这种情况下,它是self.img.Rotate()上的你的(0,0)点,但通常是它的中心图片)。 旋转角度应该是从该点到鼠标光标的线形成的角度减去用户单击时从该点到鼠标位置的线形成的角度。 要计算两点之间的角度,请使用math.atan2(y2-y1, x2-x1) ,它将以弧度为单位给出角度。 (您可能需要根据鼠标位置 ... -
旋转图像(Rotating an image)[2022-02-13]
@tada; 你可以使用css3旋转属性,如petah所说 div{ -moz-transform:rotate(90deg); -webkit-transform:rotate(90deg); -o-transform:rotate(90deg); -ms-transform:rotate(90deg); } &对于IE你可以使用IE过滤器: filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); 更多检查这些链接: http ... -
每次创建RenderTransform并重复使用它,而不是替换RenderTransform: XAML:deviceorientation事件将触发设备当前位置的更新。 这是一个演示。 请注意,这仅适用于iPhone≥4和iPad≥2。较旧的Apple硬件没有陀螺仪。 该活动还适用于Chrome和股票浏览器中的Galaxy Nexus Android 4设备。 您还可以预加载背景图像,以便立即进行切换。 The deviceorientation event fires with updates to the current position of the device. Here's a demo. Not ...您可以保存原始变换,旋转并绘制第一个图像,然后在绘制第二个图像之前应用原始变换。 尝试 AffineTransform originalTransform = g2d.getTransform(); g2d.rotate(Math.toRadians(rot), (x+15), (y+15)); g2d.drawImage(img, x, y, null); g2d.setTransform(originalTransform); g2d.drawImage(shine, x, y, null); You ...UIElement和FrameworkElement都没有Angle属性。 您需要将动画应用到RotateTransform的Angle属性。 首先,您需要创建一个转换对象:
Codename One工具栏中的无限旋转命令(或按钮)(Infinite Rotation Command (or button) in toolbar in Codename One)[2022-01-12]
您可以使用工具栏API和一点点黑客攻击。 我创建了以下方法来做到这一点: private void showTitleProgress(Toolbar t) { int pos = t.getComponentCount() - 1; //If you have a command on the left like back command //int pos = t.getComponentCount(); //If you don't have a command on the left ...工具栏图像在旋转时更新(Toolbar Image update when rotating)[2022-11-14]
两种解决方案 1)从ConfigurationChanges = ConfigChanges.ScreenSize|ConfigChanges.Orientation删除|ConfigChanges.Orientation ,这意味着您的活动将在屏幕旋转时重新创建。 2)在OnConfigurationChanged方法中,在SetImageToToolbar();之上添加以下代码SetImageToToolbar(); 方法,如下所示: public override void OnConfigu ...图像不旋转(Image is not rotating)[2023-04-18]
您正在覆盖用作源的图像(b == a)。 你需要创建一个新的。 public void rotateIMG(double d) { // Consider also using GraphicsConfiguration.createCompatibleImage(). // I'm just putting here something that should work BufferedImage b = new BufferedImage(a.getHeight(), a.get ...相关文章
更多- Memcached CAS(Check-And-Set)原子操作
- Rails 风格指导
- 用 Rails 搭建微信公众平台 API
- rails 单元测试
- 启动Solr时报 _version_ field must exist in schema 错误的解决方法
- Rails常用插件
- Rails中的路由功能是如何对应的?
- rails model的一点疑惑。。。。。
- 配置sunspot tomcat结合sunspot_rails
- Rails4 已经移出了params可以解析xml的功能,拿rails4做微信API的童鞋们注意了
最新问答
更多- h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
- 创建一个功能(Create a function)
- 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
- PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
- Qt冻结循环的原因?(Qt freezing cause of the loop?)
- TableView重复youtube-api结果(TableView Repeating youtube-api result)
- 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
- SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
- 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
- 以编程方式创建UITableView(Creating a UITableView Programmatically)
- 如何打破按钮上的生命周期循环(How to break do-while loop on button)
- C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
- 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
- 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
- Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
- 设置kotlin扩展名(Setting a kotlin extension)
- 如何并排放置两个元件?(How to position two elements side by side?)
- 如何在vim中启用python3?(How to enable python3 in vim?)
- 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
- 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
- Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
- dedecms如何安装?
- 在哪儿学计算机最好?
- 学php哪个的书 最好,本人菜鸟
- 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
- 如何覆盖错误堆栈getter(How to override Error stack getter)
- 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
- USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
- 电脑高中毕业学习去哪里培训
- 正则表达式验证SMTP响应(Regex to validate SMTP Responses)