You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With your filemaker.yml file, you can load the configuration into the registry.
require'filemaker'Filemaker.load!('./filemaker.yml',:production)server=Filemaker.registry['default']server.databases.all# Show all your databases
The registry will give you back a single server instance where you can use to tag which database and layout you want to query and write data for. Note: You can have multiple registry if you have many FileMaker server with different hostname.
api=server.database[:candidates].layout[:profile]api=server.db[:candidates].lay[:profile]# Shortcutapi=server.db[:candidates][:profile]# The same
With the api instance, you can perform find, new, edit, and delete CRUD requests.
resultset=api.find({name: 'Bob'},{max: 10})resultset.params# Useful for debugging the parameters that get send to FileMakerresultset.xml# The raw XMLresultset.countresultset.total_count
You will get back a resultset which is enumerable so you can directly iterate over your records.
resultset.eachdo |record|
name1=record[:name]name2=record['NaMe']name3=record.name# Access your portals hashrecord.portalsend
As you can see, to get back the individual field, you do not have to worry about String, Symbol, or case sensitivity.
Using Filemaker::Model
Using those low-level api can get frustrating pretty fast. If you want some sort of ORM mapping, you can include Filemaker::Model to your data model. This will give you many conveniences like a query DSL and persistence framework. You can expect your Rails form to work as well as JSON and XML serialization. Callbacks and validations are also provided.
#!/usr/bin/env rubyrequire'bundler/setup'Bundler.requireFilemaker.registry['default']=Filemaker::Server.newdo |config|
config.host=ENV['FILEMAKER_HOST']config.account_name=ENV['FILEMAKER_ACCOUNT_NAME']config.password=ENV['FILEMAKER_PASSWORD']endclassJobincludeFilemaker::Modelbefore_save:geotag_locationdatabase:jobslayout:job# Make use of kaminari gempaginates_per50# Taken from filemaker.yml config file, default to :default# Only use registry if you have multiple FileMaker servers you want to connectregistry:read_slavestring:job_id,fm_name: 'JobOrderID',identity: truestring:title,:requirementsdatetime:created_atdatetime:published_at,fm_name: 'ModifiedDate'money:salaryvalidates:title,presence: truebelongs_to:companyhas_many:applicants,class_name: 'JobApplication',reference_key: 'job_id'defgeotag_location# before_save callbackendend
The following data types are available:
string or text - String as TEXT
integer - Integer as NUMBER
number or money - BigDecimal as NUMBER
date - Date as DATE
datetime - DateTime as TIME/TIMESTAMP
object - Filemaker::Model::Types::Attachment as CONTAINER
email - Filemaker::Model::Types::Email
CONTAINER will just be a URL string.
The following data type options are available:
fm_name - Map the attribute name to the FileMaker field name
identity - Identify which attribute is to be act as an ID
The following relations are available:
has_many - Will automatically infer the identity attribute to be the reference_key
belongs_to - Will append _id to the foreign key as the reference_key
has_portal
For relation, class_name and reference_key are typically inferred, but you can override.
With Rails
In your Gemfile
gem'filemaker'gem'kaminari'# For pagination
Place filemaker.yml file into your config folder and write your data models as you would normally.
As always, the model is just for data model, it is your judgement how your want to tightly coupled it to your domain models.